@(providerId: String, loginForm: Option[Form[(String, String)]] = None)(implicit request: RequestHeader, messages: Messages, env: securesocial.core.RuntimeEnvironment)

@import securesocial.core.AuthenticationMethod._
@import play.api.Logger
@import helper._

@implicitFieldConstructor = @{ FieldConstructor(securesocial.views.html.inputFieldConstructor.f) }

@env.providers.get(providerId).map { provider =>
            @if( provider.authMethod == OAuth1 || provider.authMethod == OAuth2 ) {
                @defining( "images/providers/%s.png".format(provider.id) ) { imageUrl =>
                    <a href="@env.routes.authenticationUrl(provider.id)"> <img src="@securesocial.controllers.routes.Assets.at(imageUrl)"/></a>
                }
            }

            @if( provider.authMethod == UserPassword ) {
                <form action = "@env.routes.authenticationUrl("userpass")"
                      class="form-horizontal" autocomplete="off" method="POST">
                    <fieldset>
                        @CSRF.formField

                        @if( env.usernamePasswordConfig.withUserNameSupport ) {
                            @helper.inputText(
                                loginForm.get("username"),
                                '_label -> Messages("securesocial.signup.username"),
                                'class -> "input-xlarge"
                            )
                        } else {
                            @helper.inputText(
                                loginForm.get("username"),
                                '_label -> Messages("securesocial.signup.email1"),
                                'class -> "input-xlarge"
                            )
                        }

                        @helper.inputPassword(
                            loginForm.get("password"),
                            '_label -> Messages("securesocial.signup.password1"),
                            'class -> "input-xlarge"
                        )

                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary">@Messages("securesocial.login.title")</button>
                        </div>
                        <div class="clearfix">
                            <p><a href="@env.routes.startResetPasswordUrl">@Messages("securesocial.login.forgotPassword") </a></p>
                        </div>
                        @if(env.registrationEnabled.value){
                             <div class="clearfix">
                                 <p>@Messages("securesocial.login.signUp") <a href="@env.routes.startSignUpUrl">@Messages("securesocial.login.here")</a></p>
                              </div>
                            }
                    </fieldset>
                </form>
            }
}.getOrElse {
    @*****************************************
     * Todo: throw a runtime exception? this might need improvement
     *****************************************@
    @Logger.error("[securesocial] unknown provider '%s'. Can't render it.".format(providerId))
    { throw new RuntimeException("Unknown provider '%s') }
}
